package com.simpleframe.web;

import java.io.IOException;
import java.io.Writer;
import java.util.Collection;

public class ActionMessageDecorator {
	
	//{\"type":"error","message":"提示信息"}
	private final String SUCCESS_MSG_PREFIX = "{\"type\":\"success\",\"message\":\"";
	private final String ERROR_MSG_PREFIX = "{\"type\":\"error\",\"message\":\"";
	private final String MSG_SUFFIX = "\"}";
	
	public void success(Writer out, Collection<String> messages){
		try {
			out.write(SUCCESS_MSG_PREFIX);
			for (String message : messages) {
				out.write(message);
			}
			out.write(MSG_SUFFIX);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void error(Writer out, Collection<String> errorMessages){
		try {
			out.write(ERROR_MSG_PREFIX);
			for (String message : errorMessages) {
				out.write(message);
			}
			out.write(MSG_SUFFIX);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void date(Writer out, String date){
		
	}
}
